<%--
  Created by IntelliJ IDEA.
  User: Root404
  Date: 2023/6/1
  Time: 9:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
    注册账户<input type="text" name="name" id="name"><span style="color: red"></span>
    <br/>
    注册密码<input type="text" name="pwd" id="name1">
    <input type="button" value="注册">
   <table border="4">

   </table>
    <ul></ul>
    <form method="get" action="${pageContext.request.contextPath}/....">
        注册账户<input type="text" name="name" id="name2"><span id="spp" style="color: red"></span>
        <br/>
        注册密码<input type="text" name="pwd" id="name12">
        <input type="button" id="bt" value="注册">
        <input type="submit" value="提交">
    </form>
<%--    <fmt:formatDate value="${date}" pattern="yyyy-MM-dd"></fmt:formatDate>--%>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
    //表单序列化
    $("#bt").click(function () {
            $.getJSON(
                "${pageContext.request.contextPath}/ServletAjax11?op=xulie",
                $("form").serialize(),//表单序列化，自己把所有的值统一带过去
                function (data) {
                    if(data=="y"){
                        $("#spp").html("*对不起不能注册")
                    }else{
                        $("#spp").html("*可以注册")
                    }
                }
            );
    });
    //远程加载
    $("ul").load("Y.html");
    $("#name1").blur(function () {
        var name=$(this).val();

        $.getJSON("${pageContext.request.contextPath}/ServletAjax11?op=list&name="+name,
            function (data) {//序列化下车
                $("table").html("");
                $.each(data,function () {
                    var xx=" <tr>\n" +
                        "<td>"+this.name+"</td>\n" +
                        "       </tr>";
                    $("table").append(xx);
                })
            });
    });

    $("#name").blur(function () {
        var name=$(this).val();
        $.getJSON("${pageContext.request.contextPath}/ServletAjax11?op=find&name="+name,
        function (data) {
                if(data=="y"){
                    $("span").html("*对不起不能注册")
                }else{
                    $("span").html("*可以注册")
                }
        });
    });


</script>
</body>
</html>
